/**   
 * Copyright © 2019 eSunny Info. Tech Ltd. All rights reserved.
 * 
 * @Description:TODO(功能)
 * @className MyListener.java
 * @Package: com.erp.listener 
 * @author: yj   
 * @date: 2019年2月19日 下午1:28:51 
 */
package com.erp.listener;

import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.erp.util.TimeHelper;

/**
 * @className MyListener.java
 * @author yj
 * @Description:TODO(功能)
 * @Date 2019年2月19日
 */
public class MyListener implements ServletContextListener {

	private Timer timer;
	private MyTask myTask;
	
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		System.out.println("--开始监听--");
		timer = new Timer();
		myTask = new MyTask();
		
		timer.scheduleAtFixedRate(myTask, 0, 5000);
	}
	
	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		System.out.println("--监听销毁--");
	}

}

class MyTask extends TimerTask{

	@Override
	public void run() {
		String time = TimeHelper.getTime();
		System.out.println("时间 : "+time);
	}
	
}


